package org.jod.anarchytrek.timer;

import org.jod.anarchytrek.ITimer;
import org.jod.anarchytrek.ITimerableComponent;

public class TimerRunnable  implements Runnable,  ITimer {
    
    private ITimer _timer;
    private long _interval;
    private Thread _thread;

    public TimerRunnable(ITimer aTimer) {
        _timer = aTimer;
        _interval = 1000;
        _thread = new Thread(this);
    }

    public void start() {
        _thread.start();
        _timer.start();
    }
    
    public void stop() {
        _thread.interrupt();
        _timer.stop();
    }    
    
    public void interval(long aInterval) {
        _timer.interval(aInterval);
        _interval = aInterval;
    }
    
    public double dataStellare() {
        return _timer.dataStellare();
    }    
    
    public void run() {
        while (true) {
            try {
                Thread.sleep(_interval);
                increases();
            }
            catch (InterruptedException e) {}
        }
}

    public void increases() {
        _timer.increases();
    }

    public void register(ITimerableComponent aComponent) {
        _timer.register(aComponent);
    }





}
